﻿using System;
using System.Collections.Generic;
using System.Linq;
using DomenModel;
using System.Linq.Expressions;
using Model.Repositories.Interfaces;
using System.Data.Entity;

namespace OmsTestProject.MockRepository
{
    public class ItemDimensionRepository : ICrudItemDimension
    {
        MockRepositoryContext _db = MockRepositoryContext.MockContextInstance;
        
        public ItemDimension GetById(long Id)
        {
                ItemDimension itemDimensionById = _db.ItemDimensions.FirstOrDefault(p => p.ItemDimensionId == Id);
                return itemDimensionById;
        }

        public void Save(ItemDimension t)
        {
            if (t.ItemDimensionId== 0)
            {
                t.ItemDimensionId = _db.ItemDimensions.Count + 1;
            }
            _db.ItemDimensions.Add(t);
        }

        public void Update(ItemDimension t)
        {
                _db.ItemDimensions[t.ItemDimensionId].ItemId = t.ItemId;
                _db.ItemDimensions[t.ItemDimensionId].Item = t.Item;
                _db.ItemDimensions[t.ItemDimensionId].Price = t.Price;
                _db.ItemDimensions[t.ItemDimensionId].Quantity = t.Quantity;
                _db.ItemDimensions[t.ItemDimensionId].Dimension = t.Dimension;

        }

        public void Delete(long Id)
        {
                ItemDimension itemDimensionById = _db.ItemDimensions.FirstOrDefault(p => p.ItemDimensionId == Id);
                _db.ItemDimensions.Remove(itemDimensionById);
        }

        public ItemDimension GetByPrice(decimal price)
        {
                ItemDimension itemDimensionByPrice = _db.ItemDimensions.FirstOrDefault(p => p.Price == price);
               return itemDimensionByPrice;
        }

        public ItemDimension GetByQuantity(int quantity)
        {
                ItemDimension itemDimensionByQuantity = _db.ItemDimensions.FirstOrDefault(p => p.Quantity == quantity);
                return itemDimensionByQuantity;
        }

        public List<ItemDimension> GetCollection()
        {
                return _db.ItemDimensions;
        }

        public IQueryable<ItemDimension> GetCollectionByFilter(Expression<Func<ItemDimension, bool>> t)
        {
                var itemDimensionByFilter = _db.ItemDimensions.AsQueryable<ItemDimension>().Where(t);
                return itemDimensionByFilter;
        }
    }
}
